var url = 'http://localhost/logicsol_poll/';    
$(document).ready(function(){
    $.validator.setDefaults({
        submitHandler: function() {  
            if($('#country_ccode').val()==0){
                alert('Odaberite drÅ¾avu!');
                return false; 
            }
            $('#ajax_loader').show();
            $.ajax({
                type: 'GET',
                url: url+'nalog/nalog/kreiraj_nalog/?jsoncall=?',
                data: $('#prijavna-forma').serialize(),
                dataType: 'jsonp',
                success: function(data){
                    if(data.success=='failed'){
                        $('#after_submit_errors').show();
                        $('#after_submit_errors').html(data.message); 
                        $('#ajax_loader').hide();  
                        $('html, body').animate({scrollTop:180}, 'slow'); 
                    }else{
                        $('#after_submit_errors').show(); 
                        $('#ajax_loader').hide();
                        $('.register').fadeOut('slow');
                        $('.qoptionssmlbuttons').fadeOut('slow');
                        $('html, body').animate({scrollTop:180}, 'slow'); 
                        $('#after_submit_errors').css('border','none');
                        $('#after_submit_errors').css('width','240px');
                        $('#after_submit_errors').html('<h1 style="font-size:16px">Vaš nalog je uspešno kreiran.</h1><br /><p>Poslat Vam je email sa pristupnim podatcima.</p><p>Ukoliko imate dodatnih pitanja molimo da nas kotaktirate na support@logicsolution.rs;</p><p>Za direktnu podršku putem telefona pozovite +381 65 305 309 1.</p> ');
                    }
                },
                error:function(data){alert("Error: " + data);}
            });
            return false;
        }
    }); //KERIRAJ NOVI KORISNICKI NALOG
    $('#submit-form').live('click',function(){ $('#prijavna-forma').submit();})
    // validate signup form on keyup and submit
    $("#prijavna-forma").validate({
        rules: {
            firstname: "required",
            lastname: "required",
            address1: "required",
            zip: "required",
            city: "required",
            country_ccode: "required",
            email: "required",
            password_one: {
                required: true,
                minlength: 5,
                maxlength: 12
            },
            password_conf: {
                required: true,
                minlength: 5,
                maxlength: 12,
                equalTo: "#password_one"
            }
        },
        messages: {
            firstname: "Molimo unestite vaÅ¡e ime",
            lastname: "Molimo unestite vaÅ¡e prezime",
            address1: "Molimo unestite adresu",
            zip: "Molimo unestite poÅ¡tanski broj",
            city: "Molimo unestite grad",
            email: "unestite validnu email adresu",
            password_one: {
                required: "Molimo unesite lozinku",
                minlength: "Minimum 5 karaktera",
                maxlength: "Maximum 12 karaktera"
            },
            password_conf: {
                required: "Molimo unesite lozinku",
                minlength: "Minimum 5 karaktera",
                maxlength: "Maximum 12 karaktera",
                equalTo: "Molimo unesite istu lozinku"
            } 
        }
    }); 
});